package com.hackerrank.challenges.quicksort1partition;

// Head ends here
import java.util.*;
public class Solution {

	static void partition(int[] ar) {
		int p = ar[0], c = 0, br[] = new int[ar.length];
		for(int i = 1; i < ar.length; i++)
			if(ar[i] <= p)
				br[c++] = ar[i];
		br[c++] = p;
		for(int i = 1; i < ar.length; i++)
			if(ar[i] > p)
				br[c++] = ar[i];
		printArray(br);
	}

	// Tail starts here
	static void printArray(int[] ar) {
		for(int n: ar)
			System.out.print(n + " ");
		System.out.println("");
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] ar = new int[n];
		for(int i=0;i<n;i++)
			ar[i]=in.nextInt(); 
		partition(ar);
	}    
}
